package com.example.kaoqinmanager.activity;

import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;

import com.example.kaoqinmanager.adapter.PaiBanAdapter;
import com.example.kaoqinmanager.base.BaseBindingActivity;
import com.example.kaoqinmanager.bean.PaiBanTable;
import com.example.kaoqinmanager.databinding.ActivityPaiBanSetBinding;

import org.litepal.LitePal;

import java.util.ArrayList;
import java.util.List;

public class PaiBanSetActivity extends BaseBindingActivity<ActivityPaiBanSetBinding> {
    PaiBanAdapter paiBanAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        actionBar.setTitle("排班设置");
        //显示返回箭头默认是不显示的
        actionBar.setDisplayHomeAsUpEnabled(true);


        List<PaiBanTable> list = new ArrayList<>();
      /*  for (int i = 0; i < 30; i++) {
            list.add(new PaiBanTable());
        }*/

        paiBanAdapter = new PaiBanAdapter(this, list);
        getBinding().mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        getBinding().mRecyclerView.setAdapter(paiBanAdapter);


        getBinding().btnAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openActivity(PaiBanAddActivity.class);
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        List<PaiBanTable> tableList = LitePal.findAll(PaiBanTable.class);
        paiBanAdapter.setNewData(tableList);

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            //actionbar的左侧图标的点击事件处理
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}